<!DOCTYPE html>
<html lang="zh_cn">
  <head>
    
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">



  <meta name="description" content="利用frp内网穿透实现用自家电脑发布网站(不用买服务器了)"/>




  <meta name="keywords" content="frp内网穿透, 阿辉的博客" />










  <link rel="alternate" href="/blog/default" title="阿辉的博客">




  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=2.9.0" />



<link rel="canonical" href="http://goodbox.gitee.io/blog/2020/03/24/frp-tutorial/"/>



  <link rel="stylesheet" type="text/css" href="/blog/lib/fancybox/jquery.fancybox.css" />




  <link rel="stylesheet" type="text/css" href="/blog/lib/nprogress/nprogress.min.css" />



<link rel="stylesheet" type="text/css" href="/blog/css/style.css?v=2.9.0" />



  



  <script id="baidu_push">
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>








<script>
  window.config = {"title":"阿辉的博客","subtitle":"","description":"","author":"阿辉","language":"zh_cn","timezone":"","url":"http://goodbox.gitee.io/blog","root":"/blog/","permalink":":year/:month/:day/:title/","permalink_defaults":null,"pretty_urls":{"trailing_index":true,"trailing_html":true},"source_dir":"source","public_dir":"public","tag_dir":"tags","archive_dir":"archives","category_dir":"categories","code_dir":"downloads/code","i18n_dir":":lang","skip_render":null,"new_post_name":":title.md","default_layout":"post","titlecase":false,"external_link":{"enable":true,"field":"site","exclude":""},"filename_case":0,"render_drafts":false,"post_asset_folder":true,"relative_link":false,"future":true,"highlight":{"enable":true,"auto_detect":false,"line_number":true,"tab_replace":"","wrap":true,"hljs":false,"first_line_number":"always1"},"default_category":"uncategorized","category_map":null,"tag_map":null,"date_format":"YYYY-MM-DD","time_format":"HH:mm:ss","use_date_for_updated":false,"per_page":10,"pagination_dir":"page","theme":"even","server":{"port":4000,"log":false,"compress":false,"header":true,"cache":false},"deploy":{"type":"git","repo":"https://gitee.com/goodbox/blog.git","branch":"master"},"ignore":null,"meta_generator":true,"keywords":null,"index_generator":{"per_page":10,"order_by":"-date","path":""},"include":null,"exclude":null,"menu":{"Home":"/","Archives":"/archives/","Categories":"/categories/","Tags":"/tags","About":"/about"},"leancloud":{"baidu_analytics":"9b96b92118600aa5dae45039cebb80de","app_id":null,"app_key":null},"social":{"email":"your@email.com","stack-overflow":null,"twitter":null,"facebook":null,"linkedin":null,"google":null,"github":"https://github.com/ahonn","weibo":null,"zhihu":null,"douban":null,"pocket":null,"tumblr":null,"instagram":null},"copyright":{"enable":true,"license":"<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\" target=\"_blank\">知识共享署名-非商业性使用 4.0 国际许可协议</a>"},"archive_generator":{"per_page":10,"yearly":true,"monthly":true,"daily":false},"category_generator":{"per_page":10},"tag_generator":{"per_page":10},"marked":{"gfm":true,"pedantic":false,"breaks":true,"smartLists":true,"smartypants":true,"modifyAnchors":"","autolink":true,"sanitizeUrl":false,"headerIds":true},"since":2015,"favicon":"/favicon.ico","rss":"default","color":"Default","toc":true,"fancybox":true,"pjax":true,"reward":{"enable":false,"qrCode":{"wechat":null,"alipay":null}},"baidu_analytics":null,"baidu_verification":null,"google_analytics":null,"google_verification":null,"disqus_shortname":null,"changyan":{"appid":null,"appkey":null},"livere_datauid":null,"version":"2.9.0"};
</script>

    <title> 利用frp内网穿透实现用自家电脑发布网站(不用买服务器了) - 阿辉的博客 </title>
  <meta name="generator" content="Hexo 4.2.0"></head>

  <body><div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/blog/." class="logo">阿辉的博客</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    
      <a href="/blog/">
        <li class="mobile-menu-item">
          
          
            首页
          
        </li>
      </a>
    
      <a href="/blog/archives/">
        <li class="mobile-menu-item">
          
          
            归档
          
        </li>
      </a>
    
      <a href="/blog/categories/">
        <li class="mobile-menu-item">
          
          
            分类
          
        </li>
      </a>
    
      <a href="/blog/tags">
        <li class="mobile-menu-item">
          
          
            标签
          
        </li>
      </a>
    
      <a href="/blog/about">
        <li class="mobile-menu-item">
          
          
            关于
          
        </li>
      </a>
    
  </ul>
</nav>

    <div class="container" id="mobile-panel">
      <header id="header" class="header"><div class="logo-wrapper">
  <a href="/blog/." class="logo">阿辉的博客</a>
</div>

<nav class="site-navbar">
  
    <ul id="menu" class="menu">
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/">
            
            
              首页
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/archives/">
            
            
              归档
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/categories/">
            
            
              分类
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/tags">
            
            
              标签
            
          </a>
        </li>
      
        <li class="menu-item">
          <a class="menu-item-link" href="/blog/about">
            
            
              关于
            
          </a>
        </li>
      
    </ul>
  
</nav>

      </header>

      <main id="main" class="main">
        <div class="content-wrapper">
          <div id="content" class="content">
            
  
  <article class="post">
    <header class="post-header">
      <h1 class="post-title">
        
          利用frp内网穿透实现用自家电脑发布网站(不用买服务器了)
        
      </h1>

      <div class="post-meta">
        <span class="post-time">
          2020-03-24
        </span>
        
          <div class="post-category">
            
              <a href="/blog/categories/frp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">frp内网穿透</a>
            
          </div>
        
        
      </div>
    </header>

    
    


    <div class="post-content">
      
        <p>利用frp内网穿透实现用自家电脑发布网站(不用买服务器了)<br><code>一直想总结一下使用frp的经验，今天来写一下
我的yiiu.co域名的网站都是用frp做的内网穿透实现的，服务器就在我身边，发布的网站服务外网都访问，下面就来说说我的配置方法</code></p>
<a id="more"></a>
<p>下载frp<br>这个不多说，选择好自己的平台就可以了，注意版本号一定要一致，下载地址<br><a href="https://github.com/fatedier/frp/releases" target="_blank" rel="noopener">https://github.com/fatedier/frp/releases</a></p>
<p>打开可以看到 linux 平台有很多版本，386, amd64, arm, arm64 等等，这里说一下，如果你服务器是32位，就下载 386，如果你服务器是64位的，而且你又不能分清cpu是arm架构的还是amd架构的，那也选386</p>
<p>总之一句话，对系统架构分不清的就只下载386的就对了</p>
<p>解压下载好的压缩包，可以看到几个文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">.</span><br><span class="line">├── LICENSE</span><br><span class="line">├── frpc</span><br><span class="line">├── frpc.ini</span><br><span class="line">├── frpc_full.ini</span><br><span class="line">├── frps</span><br><span class="line">├── frps.ini</span><br><span class="line">└── frps_full.ini</span><br></pre></td></tr></table></figure>
<p>各文件说明</p>
<pre><code>LICENSE 版权说明文件
frpc 客户端启动命令
frpc.ini 客户端配置文件
frpc_full.ini 客户端配置文件参考文件
frps 服务端启动命令
frps.ini 服务端配置文件
frps_full.ini 服务端配置文件参考文件</code></pre><p>frp运行流程<br>做内网穿透需要事先准备的</p>
<p>一台外网服务器<br>一台内网服务器<br>一次请求的经过，最简单的流程</p>
<p>用户请求(浏览器) -&gt; 外网服务器ip -&gt; 外网服务器上部署的frps -&gt; 内网服务器上部署的frpc -&gt; 内网服务器上部署的服务</p>
<p>请求成功后，响应过程与请求过程相反</p>
<p>这个过程中还可以加上 nginx 来做不同域名共用80端口的转发工作，那样就会变成</p>
<p>用户请求(浏览器) -&gt; 外网服务器ip -&gt; 外网服务器nginx -&gt; 外网服务器上部署的frps -&gt; 内网服务器上部署的frpc -&gt; 内网服务器nginx -&gt; 内网服务器上部署的服务</p>
<p>好了明白这些了，就可以来做配置了</p>
<p>##配置frps<br>想办法把 frps frps.ini 拷贝到外网服务器上</p>
<p>我这假设放在 /opt/frp/ 下，假设外网服务器ip是 10.10.10.10, 假设网站域名是 example.com</p>
<p>修改 frps.ini</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line">bind_port &#x3D; 7000</span><br><span class="line">dashboard_port &#x3D; 7500</span><br><span class="line">dashboard_user &#x3D; admin</span><br><span class="line">dashboard_pwd &#x3D; 123123</span><br><span class="line">token &#x3D; 123123</span><br><span class="line">vhost_http_port &#x3D; 8000</span><br><span class="line">subdomain_host &#x3D; example.com</span><br></pre></td></tr></table></figure>
<pre><code>bind_port frps启动时要占用的端口
dashboard_port frps启动后管理后台的端口
dashboard_user frps启动后管理后台登录的用户名
dashboard_pwd frps启动后管理后台登录的密码
token frpc连接frps时要用到的令牌，如果不设置任何一个frpc都能连进来就不安全了
vhost_http_port frps转发的内网服务的端口
subdomain_host 你的域名</code></pre><p>##然后启动 frps</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 给frps附上可执行权限</span><br><span class="line">sudo chmod +x frps</span><br><span class="line"># 在后台运行并将日志写入到当前目录下的 log.file 里</span><br><span class="line">.&#x2F;frps -c frps.ini &gt; log.file 2&gt;&amp;1 &amp;</span><br></pre></td></tr></table></figure>
<p>##配置frpc<br>想办法把 frpc frpc.ini 拷贝到内网服务器上</p>
<p>我这假设放在 /opt/frp/ 下, 假设要配置的网站域名是 example.com bbs.example.com blog.example.com 三个域名</p>
<p>修改 frpc.ini</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line">server_addr &#x3D; 10.10.10.10</span><br><span class="line">server_port &#x3D; 7000</span><br><span class="line">token &#x3D; 123123</span><br><span class="line"></span><br><span class="line">[example]</span><br><span class="line">type &#x3D; http</span><br><span class="line">local_ip &#x3D; localhost</span><br><span class="line">local_port &#x3D; 8080</span><br><span class="line">use_encryption &#x3D; false</span><br><span class="line">use_compression &#x3D; true</span><br><span class="line">subdomain &#x3D; example.com</span><br><span class="line"></span><br><span class="line">[bbs]</span><br><span class="line">type &#x3D; http</span><br><span class="line">local_ip &#x3D; localhost</span><br><span class="line">local_port &#x3D; 8081</span><br><span class="line">use_encryption &#x3D; false</span><br><span class="line">use_compression &#x3D; true</span><br><span class="line">subdomain &#x3D; bbs</span><br><span class="line"></span><br><span class="line">[blog]</span><br><span class="line">type &#x3D; http</span><br><span class="line">local_ip &#x3D; localhost</span><br><span class="line">local_port &#x3D; 8082</span><br><span class="line">use_encryption &#x3D; false</span><br><span class="line">use_compression &#x3D; true</span><br><span class="line">subdomain &#x3D; blog</span><br></pre></td></tr></table></figure>
<p>相关配置说明</p>
<pre><code>server_addr 外网服务器的ip，也就是frps所在服务器的ip
server_port frps.ini 上配置的 bind_port
token 必须跟在 frps.ini 里配置的 token 一致，否则会导致连不上frps
use_encryption 是否使用加密，我这没用，因为我在外网通过nginx配置了https所以内网的服务都是http的
use_compression 是否使用压缩，使用了网站响应数据会小一些，网站速度也会更快一些
subdomain 二级域名的名字</code></pre><p>启动 frpc</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"># 给frps附上可执行权限</span><br><span class="line">sudo chmod +x frpc</span><br><span class="line"># 在后台运行并将日志写入到当前目录下的 log.file 里</span><br><span class="line">.&#x2F;frpc -c frpc.ini &gt; log.file 2&gt;&amp;1 &amp;</span><br></pre></td></tr></table></figure>
<p>注意：内网服务器上要启动三个web服务，分别端口对应 8080, 8081, 8082</p>
<p>##映射ssh<br>如果我们不在内网服务器旁边，web服务要是出问题了，会比较麻烦，这时可以通过frp映射一个ssh，这样就可以随时随地的操作内网了</p>
<p>只需要配置frpc.ini 即可</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">[common]</span><br><span class="line">...</span><br><span class="line"></span><br><span class="line">[ssh]</span><br><span class="line">type &#x3D; tcp</span><br><span class="line">local_ip &#x3D; localhost</span><br><span class="line">local_port &#x3D; 22</span><br><span class="line">remote_port &#x3D; 7001</span><br><span class="line"></span><br><span class="line">[example]</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<p>同样的方法还可以映射游戏，同样的使用 type = tcp 把端口改成游戏的端口就可以了，比如Minecraft的端口是25565，是不是相当的方便，快跟小伙伴组队吧</p>
<p>重启 frpc , 然后就可以使用命令 ssh -p 7001 <a href="mailto:root@10.10.10.10">root@10.10.10.10</a> 来连接内网的终端了</p>
<p>总结<br>你可以通过访问 <a href="http://10.10.10.10:7500" target="_blank" rel="noopener">http://10.10.10.10:7500</a> 然后输入 frps.ini 里配置的 dashboard_user dashboard_pwd 来查看frp的运行情况<br>在启动frpc之前，你要在域名提供商那把域名解析到外网服务器上<br>如果ssh映射连接总是超时，要看一下外网服务器是否把7001端口开放了，有可能是外网服务器的防火墙拦住了<br>关于nginx配置https，参见：<a href="https://tomoya92.github.io/2016/08/28/letsencrypt-nginx-https/" target="_blank" rel="noopener">https://tomoya92.github.io/2016/08/28/letsencrypt-nginx-https/</a><br>问题<br>如果使用nginx反代frp的话，有时候会碰到这样的错误 [W] [http.go:95] do http proxy request error: no such domain: 127.0.0.1</p>
<p>这个问题我在issues里找到了解决办法，在nginx代理的时候，加上一个配置 proxy_set_header Host $host; 写在 proxy_pass 这一层就可以了</p>
<p>参见：<a href="https://github.com/fatedier/frp/issues/1521" target="_blank" rel="noopener">https://github.com/fatedier/frp/issues/1521</a></p>
<p>参考<br><a href="https://github.com/fatedier/frp/blob/master/README_zh.md" target="_blank" rel="noopener">https://github.com/fatedier/frp/blob/master/README_zh.md</a></p>

      
    </div>

    
      
      

  <div class="post-copyright">
    <p class="copyright-item">
      <span>原文作者: </span>
      <a href="http://goodbox.gitee.io/blog">阿辉</a>
    </p>
    <p class="copyright-item">
      <span>原文链接: </span>
      <a href="http://goodbox.gitee.io/blog/2020/03/24/frp-tutorial/">http://goodbox.gitee.io/blog/2020/03/24/frp-tutorial/</a>
    </p>
    <p class="copyright-item">
      <span>许可协议: </span>
      
      <a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>
    </p>
  </div>



      
      
    

    
      <footer class="post-footer">
        
          <div class="post-tags">
            
              <a href="/blog/tags/frp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/">frp内网穿透</a>
            
          </div>
        
        
        
  <nav class="post-nav">
    
    
      <a class="next" href="/blog/2020/03/24/spring-boot-plugin/">
        <span class="next-text nav-default">spring-boot 项目利用spring切面实现插件功能，对项目无侵入</span>
        <span class="prev-text nav-mobile">下一篇</span>
        <i class="iconfont icon-right"></i>
      </a>
    
  </nav>

      </footer>
    

  </article>


          </div>
          
  <div class="comments" id="comments">
    
  </div>


        </div>
      </main>

      <footer id="footer" class="footer">

  <div class="social-links">
    
      
        
          <a href="mailto:your@email.com" class="iconfont icon-email" title="email"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
        
          <a href="https://github.com/ahonn" target="_blank" rel="noopener" class="iconfont icon-github" title="github"></a>
        
      
    
      
    
      
    
      
    
      
    
      
    
      
    
    
    
      
      <a href="/blog/atom.xml" class="iconfont icon-rss" title="rss"></a>
    
  </div>


<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 - 
    <a class="theme-link" href="https://github.com/ahonn/hexo-theme-even" target="_blank" rel="noopener">Even</a>
  </span>

  <span class="copyright-year">
    
    &copy; 
     
      2015 - 
    
    2020

    <span class="heart">
      <i class="iconfont icon-heart"></i>
    </span>
    <span class="author">阿辉</span>
  </span>
</div>

      </footer>

      <div class="back-to-top" id="back-to-top">
        <i class="iconfont icon-up"></i>
      </div>
    </div>

    
  
  

  



    
  



  
  





  
    <script type="text/javascript" src="/blog/lib/jquery/jquery.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/slideout/slideout.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/fancybox/jquery.fancybox.pack.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/pjax/jquery.pjax.min.js"></script>
  

  
    <script type="text/javascript" src="/blog/lib/nprogress/nprogress.min.js"></script>
  


    <script type="text/javascript" src="/blog/js/src/even.js?v=2.9.0"></script>

  </body>
</html>
